package com.klw.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.klw.common.annotation.Log;
import com.klw.common.core.controller.BaseController;
import com.klw.common.core.domain.AjaxResult;
import com.klw.common.enums.BusinessType;
import com.klw.business.domain.KlwDepartment;
import com.klw.business.service.IKlwDepartmentService;
import com.klw.common.utils.poi.ExcelUtil;
import com.klw.common.core.page.TableDataInfo;

/**
 * 院系Controller
 * 
 * @author klw
 * @date 2025-08-24
 */
@RestController
@RequestMapping("/base/department")
public class KlwDepartmentController extends BaseController
{
    @Autowired
    private IKlwDepartmentService klwDepartmentService;

    /**
     * 查询院系列表
     */
    @PreAuthorize("@ss.hasPermi('base:department:list')")
    @GetMapping("/list")
    public TableDataInfo list(KlwDepartment klwDepartment)
    {
        startPage();
        List<KlwDepartment> list = klwDepartmentService.selectKlwDepartmentList(klwDepartment);
        return getDataTable(list);
    }

    /**
     * 导出院系列表
     */
    @PreAuthorize("@ss.hasPermi('base:department:export')")
    @Log(title = "院系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KlwDepartment klwDepartment)
    {
        List<KlwDepartment> list = klwDepartmentService.selectKlwDepartmentList(klwDepartment);
        ExcelUtil<KlwDepartment> util = new ExcelUtil<KlwDepartment>(KlwDepartment.class);
        util.exportExcel(response, list, "院系数据");
    }

    /**
     * 获取院系详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:department:query')")
    @GetMapping(value = "/{departmentId}")
    public AjaxResult getInfo(@PathVariable("departmentId") Long departmentId)
    {
        return success(klwDepartmentService.selectKlwDepartmentByDepartmentId(departmentId));
    }

    /**
     * 新增院系
     */
    @PreAuthorize("@ss.hasPermi('base:department:add')")
    @Log(title = "院系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KlwDepartment klwDepartment)
    {
        return toAjax(klwDepartmentService.insertKlwDepartment(klwDepartment));
    }

    /**
     * 修改院系
     */
    @PreAuthorize("@ss.hasPermi('base:department:edit')")
    @Log(title = "院系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KlwDepartment klwDepartment)
    {
        return toAjax(klwDepartmentService.updateKlwDepartment(klwDepartment));
    }

    /**
     * 删除院系
     */
    @PreAuthorize("@ss.hasPermi('base:department:remove')")
    @Log(title = "院系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{departmentIds}")
    public AjaxResult remove(@PathVariable Long[] departmentIds)
    {
        return toAjax(klwDepartmentService.deleteKlwDepartmentByDepartmentIds(departmentIds));
    }
}
